﻿using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using ARchGL.Platform.Authentication.TwoFactor.Google;
using ARchGL.Platform.Authorization;
using ARchGL.Platform.Authorization.Roles;
using ARchGL.Platform.Authorization.Users;
using ARchGL.Platform.Editions;
using ARchGL.Platform.MultiTenancy;

namespace ARchGL.Platform.Identity
{
    public static class IdentityRegistrar
    {
        public static IdentityBuilder Register(IServiceCollection services)
        {
            services.AddLogging();

            return services.AddAbpIdentity<Tenant, User, Role>(options =>
                {
                    // 配置身份选项
                    // 密码配置
                    //options.Password.RequireDigit = false;//是否需要数字(0-9).
                    //options.Password.RequiredLength = 6;//设置密码长度最小为6
                    //options.Password.RequireNonAlphanumeric = false;//是否包含非字母或数字字符。
                    //options.Password.RequireUppercase = false;//是否需要大写字母(A-Z).
                    //options.Password.RequireLowercase = false;//是否需要小写字母(a-z).

                    options.Tokens.ProviderMap[GoogleAuthenticatorProvider.Name] = new TokenProviderDescriptor(typeof(GoogleAuthenticatorProvider));
                })
                .AddAbpTenantManager<TenantManager>()
                .AddAbpUserManager<UserManager>()
                .AddAbpRoleManager<RoleManager>()
                .AddAbpEditionManager<EditionManager>()
                .AddAbpUserStore<UserStore>()
                .AddAbpRoleStore<RoleStore>()
                .AddAbpSignInManager<SignInManager>()
                .AddAbpUserClaimsPrincipalFactory<UserClaimsPrincipalFactory>()
                .AddAbpSecurityStampValidator<SecurityStampValidator>()
                .AddPermissionChecker<PermissionChecker>()
                .AddDefaultTokenProviders();
        }
    }
}
